<?php
///关于标收费信息的统计
if(!isset($dbselect)) //前面没设置 数据库 则指定使用 DB3
    $dbselect   = Db::G3();
$sfwhere      = "";
if($startdate!="" && $enddate!=""){
  $sfwhere    = " and qtime_h>='$startdate' and  qtime_h<='$enddate'";  
} 
$rows = $dbselect->GetRows("SELECT 
sum(if(flowty='lixiglf' ,-money,0)) as 利息管理费, sum(if(flowty='lixiglf',1,0))  as 管理费次数,
sum(if(flowty='vip' and fuid_isBorrower(uid),-money,0)) as 会员费, sum(if(flowty='vip' and fuid_isBorrower(uid),1,0))  as 会员次数,
sum(if(flowty='vip' ,-money,0)) as 会员费a, sum(if(flowty='vip',1,0))  as 会员次数a,
sum(if(flowty='koukuan',-money,0)) as 其他扣费, sum(if(flowty='koukuan',1,0))  as 扣费次数,
sum(if(flowty='zhongjiefh',-money,0)) as 中介返点, sum(if(flowty='zhongjiefh',1,0))  as 中介返点次数,
sum(if(flowty='cuifaxi',-money,0)) as 催收罚息, sum(if(flowty='cuifaxi',1,0))  as 催收罚息次数,
sum(if(flowty='returnvip' and fuid_isBorrower(uid),money,0)) as 会员返还费, sum(if(flowty='vip' and fuid_isBorrower(uid),1,0))  as 会员返还次数,
sum(if(flowty='buchang',money,0)) as 特殊补偿费, sum(if(flowty='buchang',1,0))  as 特殊补偿费次数,
sum(if(flowty='qingsuan',-money,0)) as 清算费用, sum(if(flowty='qingsuan',1,0))  as 清算次数,
sum(if(flowty='jiangli',money,0)) as 网站奖励, sum(if(flowty='jiangli',1,0))  as 网站奖励次数,
sum(if(flowty='ruochefei',-money,0)) as 拖车费, sum(if(flowty='ruochefei',1,0))  as 拖车费次数,
sum(if(flowty='zhjianmian',money,0)) as 账户减免, sum(if(flowty='zhjianmian',1,0)) as 减免次数,
sum(if(flowty='diyafeiback',money,0)) as 押金返回, sum(if(flowty='diyafeiback',1,0))as 押金返回次数,
sum(if(flowty='returnfxj',money,0)) as 风险金返回, sum(if(flowty='returnfxj',1,0))as 风险金返回次数,
sum(if(flowty='returntcf',money,0)) as 停车费返回, sum(if(flowty='returntcf',1,0))as 停车费返回次数,
sum(if(flowty='returnglf',money,0)) as 管理费返回, sum(if(flowty='returnglf',1,0))as 管理费返回次数,
sum(if(flowty='maichekuisun',money,0)) as 卖车亏损, sum(if(flowty='maichekuisun',1,0))as 卖车亏损次数,
sum(if(flowty='bukoutcf',-money,0)) as 补扣停车费, sum(if(flowty='bukoutcf',1,0))as 补扣停车次数,
sum(if(flowty='bukouglf',-money,0)) as 补扣管理费, sum(if(flowty='bukouglf',1,0))as 补扣管理次数,
sum(if(flowty='jiajitixian',-money,0)) as 加急提现费, sum(if(flowty='jiajitixian',1,0))as 加急提现次数,
sum(if(flowty='dianzhissback',-money,0)) as 垫资损失收回费, sum(if(flowty='dianzhissback',1,0))as 垫资损失收回次数,
sum(if(flowty='huodongjiangli',money,0)) as 活动红包支出费用, sum(if(flowty='huodongjiangli',1,0))as 活动红包支出费用次数,
sum(if(flowty='lc_redeem_manage_fee',money,0)) as 理财利息管理费, sum(if(flowty='lc_redeem_manage_fee',1,0))as 理财利息管理费次数,
sum(if(flowty='lc_redeem_fee',money,0)) as 赎回手续费, sum(if(flowty='lc_redeem_fee',1,0))as 赎回手续费次数,
SUBSTR( qtime_h, 1, 10 ) as qtime_h
FROM  `04a_5flow_uid` f 
WHERE `flowty` in ('lixiglf','vip','koukuan','zhongjiefh','cuifaxi','returnvip','buchang','qingsuan','jiangli','ruochefei','zhjianmian','diyafeiback','returnfxj','returntcf','returnglf','bukoutcf','maichekuisun','bukouglf','jiajitixian','dianzhissback','huodongjiangli','lc_redeem_manage_fee','lc_redeem_fee') $sfwhere
group by SUBSTR( qtime_h, 1, 10 )");
foreach($rows as &$row){
    $ctime  = $row['qtime_h'];
    $count  = $row['管理费次数'];
    $co_hy  = $row['会员次数'];
    $co_hya = $row['会员次数a'];
    $co_ot  = $row['扣费次数'];
    $co_bc  = $row['会员返还次数'];
    $co_ts  = $row['特殊补偿费次数'];
    $co_qs  = $row['清算次数'];
    $co_wj  = $row['网站奖励次数'];
    $co_tc  = $row['拖车费次数'];
    $co_jm  = $row['减免次数'];
    $c_b_u  = $row['押金返回次数'];
    $c_b_f  = $row['风险金返回次数'];
    $c_b_t  = $row['停车费返回次数'];
    $c_b_g  = $row['管理费返回次数'];
    $c_b_zj = $row['中介返点次数'];
    $c_b_cf = $row['催收罚息次数'];
    $c_b_mk = $row['卖车亏损次数'];
    $c_b_bk = $row['补扣停车次数'];
    $c_b_gl = $row['补扣管理次数'];
    $c_j_tx = $row['加急提现次数'];
    $c_d_ss = $row['垫资损失收回次数'];
    $c_h_hb = $row['活动红包支出费用次数'];
    $c_lx_glf = $row['理财利息管理费次数'];
    $c_re_sxf = $row['赎回手续费次数'];
    ///对于标一些特殊的资金变动的特殊统计 
    CTLog::G()->pxxDayReal($count.",sid",1,"利息管理费",$row['利息管理费'],$ctime);
    if($c_b_u>0){
        CTLog::G()->pxxDayReal($c_b_u.",sid",1,"网站_返还_押金",$row['押金返回'],$ctime);
    }
    if($c_b_f>0){ 
        CTLog::G()->pxxDayReal($c_b_f.",sid",1,"网站_返还_风险金",$row['风险金返回'],$ctime);
    }
    if($c_b_t>0){
        CTLog::G()->pxxDayReal($c_b_t.",sid",1,"网站_返还_停车费",$row['停车费返回'],$ctime);
    }
    if($c_b_g>0){
        CTLog::G()->pxxDayReal($c_b_g.",sid",1,"网站_返还_管理费",$row['管理费返回'],$ctime);
    }
    if($co_bc>0){ 
        CTLog::G()->pxxDayReal($co_bc.",sid",1,"网站_返还_会员费",$row['会员返还费'],$ctime);
    }
    if($co_jm>0){
        CTLog::G()->pxxDayReal($co_jm.",sid",1,"网站_支出_账户减免",$row['账户减免'],$ctime);
    }
    if($co_ts>0){ 
        CTLog::G()->pxxDayReal($co_ts.",sid",1,"网站_支出_特殊补偿费",$row['特殊补偿费'],$ctime);
    }
    if($c_b_mk>0){
        CTLog::G()->pxxDayReal($c_b_mk.",sid",1,"网站_支出_买车亏损",$row['卖车亏损'],$ctime);
    }
    if($co_wj>0){ 
        CTLog::G()->pxxDayReal($co_wj.",sid",1,"网站_支出_网站奖励",$row['网站奖励'],$ctime);
    }
    if($co_hy>0){
        CTLog::G()->pxxDayReal($co_hy.",sid",1,"网站_收费_会员费",$row['会员费'],$ctime);
    }
    if($co_hya>0){
        CTLog::G()->pxxDayReal($co_hya.",sid",1,"网站_收费_会员费_全",$row['会员费a'],$ctime);
    }
    if($co_ot>0){
        CTLog::G()->pxxDayReal($co_ot.",sid",1,"网站_收费_其他扣费",$row['其他扣费'],$ctime);
    }
    if($co_qs>0){  
        CTLog::G()->pxxDayReal($co_qs.",sid",1,"网站_收费_清算",$row['清算费用'],$ctime);
    }
    if($co_tc>0){ 
        CTLog::G()->pxxDayReal($co_tc.",sid",1,"网站_收费_拖车费",$row['拖车费'],$ctime);
    }
    if($c_b_zj>0){
        CTLog::G()->pxxDayReal($c_b_zj.",sid",1,"网站_收费_中介返点_用户",$row['中介返点'],$ctime);
    }
    if($c_b_cf>0){
        CTLog::G()->pxxDayReal($c_b_cf.",sid",1,"网站_收费_催收罚息",$row['催收罚息'],$ctime);
    }
    if($c_b_bk>0){
        CTLog::G()->pxxDayReal($c_b_bk.",sid",1,"网站_收费_补扣停车",$row['补扣停车费'],$ctime);
    }
    if($c_b_gl>0){
        CTLog::G()->pxxDayReal($c_b_gl.",sid",1,"网站_收费_补扣管理",$row['补扣管理费'],$ctime);
    }
    if($c_j_tx>0){
        CTLog::G()->pxxDayReal($c_j_tx.",sid",1,"网站_收费_加急提现",$row['加急提现费'],$ctime);
    }
    if($c_d_ss>0){
        CTLog::G()->pxxDayReal($c_d_ss.",sid",1,"网站_收费_垫资损失收回",$row['垫资损失收回费'],$ctime);
    }
    if($c_h_hb>0){
        CTLog::G()->pxxDayReal($c_h_hb.",sid",1,"网站_支出_活动红包",$row['活动红包支出费用'],$ctime);
    }
    if($c_lx_glf>0){
        CTLog::G()->pxxDayReal($c_lx_glf.",sid",1,"利息管理费",$row['理财利息管理费'],$ctime);
    }
    if($c_re_sxf>0){
        CTLog::G()->pxxDayReal($c_re_sxf.",sid",1,"赎回手续费",$row['赎回手续费'],$ctime);
    }
}

$rows = $dbselect->GetRows("SELECT 
sum(if(flowty='lixiglf' ,-money,0)) as 利息管理费, sum(if(flowty='lixiglf',1,0))  as 管理费次数,
sum(if(flowty='vip' and fuid_isBorrower(uid),-money,0)) as 会员费, sum(if(flowty='vip' and fuid_isBorrower(uid),1,0))  as 会员次数,
sum(if(flowty='vip' ,-money,0)) as 会员费a, sum(if(flowty='vip',1,0))  as 会员次数a,
sum(if(flowty='koukuan',-money,0)) as 其他扣费, sum(if(flowty='koukuan',1,0))  as 扣费次数,
sum(if(flowty='zhongjiefh',-money,0)) as 中介返点, sum(if(flowty='zhongjiefh',1,0))  as 中介返点次数,
sum(if(flowty='cuifaxi',-money,0)) as 催收罚息, sum(if(flowty='cuifaxi',1,0))  as 催收罚息次数,
sum(if(flowty='returnvip' and fuid_isBorrower(uid),money,0)) as 会员返还费, sum(if(flowty='vip' and fuid_isBorrower(uid),1,0))  as 会员返还次数,
sum(if(flowty='buchang',money,0)) as 特殊补偿费, sum(if(flowty='buchang',1,0))  as 特殊补偿费次数,
sum(if(flowty='qingsuan',-money,0)) as 清算费用, sum(if(flowty='qingsuan',1,0))  as 清算次数,
sum(if(flowty='jiangli',money,0)) as 网站奖励, sum(if(flowty='jiangli',1,0))  as 网站奖励次数,
sum(if(flowty='ruochefei',-money,0)) as 拖车费, sum(if(flowty='ruochefei',1,0))  as 拖车费次数,
sum(if(flowty='zhjianmian',money,0)) as 账户减免, sum(if(flowty='zhjianmian',1,0)) as 减免次数,
sum(if(flowty='diyafeiback',money,0)) as 押金返回, sum(if(flowty='diyafeiback',1,0))as 押金返回次数,
sum(if(flowty='returnfxj',money,0)) as 风险金返回, sum(if(flowty='returnfxj',1,0))as 风险金返回次数,
sum(if(flowty='returntcf',money,0)) as 停车费返回, sum(if(flowty='returntcf',1,0))as 停车费返回次数,
sum(if(flowty='returnglf',money,0)) as 管理费返回, sum(if(flowty='returnglf',1,0))as 管理费返回次数,
sum(if(flowty='maichekuisun',money,0)) as 卖车亏损, sum(if(flowty='maichekuisun',1,0))as 卖车亏损次数,
sum(if(flowty='bukoutcf',-money,0)) as 补扣停车费, sum(if(flowty='bukoutcf',1,0))as 补扣停车次数,
sum(if(flowty='bukouglf',-money,0)) as 补扣管理费, sum(if(flowty='bukouglf',1,0))as 补扣管理次数,
sum(if(flowty='jiajitixian',-money,0)) as 加急提现费, sum(if(flowty='jiajitixian',1,0))as 加急提现次数,
sum(if(flowty='dianzhissback',-money,0)) as 垫资损失收回费, sum(if(flowty='dianzhissback',1,0))as 垫资损失收回次数,
sum(if(flowty='huodongjiangli',money,0)) as 活动红包支出费用, sum(if(flowty='huodongjiangli',1,0))as 活动红包支出费用次数,
sum(if(flowty='lc_redeem_manage_fee',money,0)) as 理财利息管理费, sum(if(flowty='lc_redeem_manage_fee',1,0))as 理财利息管理费次数,
sum(if(flowty='lc_redeem_fee',money,0)) as 赎回手续费, sum(if(flowty='lc_redeem_fee',1,0))as 赎回手续费次数,
cid,SUBSTR( qtime_h, 1, 10 ) as qtime_h
FROM  `04a_5flow_uid` f  
WHERE  `flowty` in ('vip','koukuan','zhongjiefh','cuifaxi','returnvip','buchang','qingsuan','jiangli','ruochefei','zhjianmian','diyafeiback','returnfxj','returntcf','returnglf','bukoutcf','maichekuisun','bukouglf','jiajitixian','dianzhissback') $sfwhere
group by cid,SUBSTR( qtime_h, 1, 10 )");
foreach($rows as &$row){
    $ctime  = $row['qtime_h'];
    $count  = $row['管理费次数'];
    $co_hy  = $row['会员次数'];
    $co_hya = $row['会员次数a'];
    $co_ot  = $row['扣费次数'];
    $co_bc  = $row['会员返还次数'];
    $co_ts  = $row['特殊补偿费次数'];
    $co_qs  = $row['清算次数'];
    $co_wj  = $row['网站奖励次数'];
    $co_tc  = $row['拖车费次数'];
    $co_jm  = $row['减免次数'];
    $c_b_u  = $row['押金返回次数'];
    $c_b_f  = $row['风险金返回次数'];
    $c_b_t  = $row['停车费返回次数'];
    $c_b_g  = $row['管理费返回次数'];
    $c_b_zj = $row['中介返点次数'];
    $c_b_cf = $row['催收罚息次数'];
    $c_b_mk = $row['卖车亏损次数'];
    $c_b_bk = $row['补扣停车次数'];
    $c_b_gl = $row['补扣管理次数'];
    $c_j_tx = $row['加急提现次数'];
    $c_d_ss = $row['垫资损失收回次数'];
    $c_h_hb = $row['活动红包支出费用次数'];
    $c_lx_glf = $row['理财利息管理费次数'];
    $c_re_sxf = $row['赎回手续费次数'];
    CTLog::G()->pxxDayReal($count.",cid",$cid,"利息管理费",$row['利息管理费'],$ctime);  
    if($c_b_f>0){ 
        CTLog::G()->pxxDayReal($c_b_f.",cid",$cid,"网站_返还_风险金",$row['风险金返回'],$ctime);
    }
    if($c_b_t>0){
        CTLog::G()->pxxDayReal($c_b_t.",cid",$cid,"网站_返还_停车费",$row['停车费返回'],$ctime);
    }
    if($c_b_g>0){
        CTLog::G()->pxxDayReal($c_b_g.",cid",$cid,"网站_返还_管理费",$row['管理费返回'],$ctime);
    }
    if($co_bc>0){ 
        CTLog::G()->pxxDayReal($co_bc.",cid",$cid,"网站_返还_会员费",$row['会员返还费'],$ctime);
    }
    if($co_jm>0){
        CTLog::G()->pxxDayReal($co_jm.",cid",$cid,"网站_支出_账户减免",$row['账户减免'],$ctime);
    }
    if($co_ts>0){ 
        CTLog::G()->pxxDayReal($co_ts.",cid",$cid,"网站_支出_特殊补偿费",$row['特殊补偿费'],$ctime);
    }
    if($c_b_mk>0){
        CTLog::G()->pxxDayReal($c_b_mk.",cid",$cid,"网站_支出_买车亏损",$row['卖车亏损'],$ctime);
    }
    if($co_wj>0){ 
        CTLog::G()->pxxDayReal($co_wj.",cid",$cid,"网站_支出_网站奖励",$row['网站奖励'],$ctime);
    }
    if($count>0){
        CTLog::G()->pxxDayReal($count.",cid",$cid,"网站_收费_会员费",$row['会员费'],$ctime);
    }
    if($co_hya>0){
        CTLog::G()->pxxDayReal($co_hya.",sid",1,"网站_收费_会员费_全",$row['会员费a'],$ctime);
    }
    if($co_ot>0){
        CTLog::G()->pxxDayReal($co_ot.",cid",$cid,"网站_收费_其他扣费",$row['其他扣费'],$ctime);
    }
    if($co_qs>0){  
        CTLog::G()->pxxDayReal($co_qs.",cid",$cid,"网站_收费_清算",$row['清算费用'],$ctime);
    }
    if($co_tc>0){ 
        CTLog::G()->pxxDayReal($co_tc.",cid",$cid,"网站_收费_拖车费",$row['拖车费'],$ctime);
    }
    if($c_b_zj>0){
        CTLog::G()->pxxDayReal($c_b_zj.",cid",$cid,"网站_收费_中介返点_用户",$row['中介返点'],$ctime);
    }
    if($c_b_cf>0){
        CTLog::G()->pxxDayReal($c_b_cf.",cid",$cid,"网站_收费_催收罚息",$row['催收罚息'],$ctime);
    }
    if($c_b_bk>0){
        CTLog::G()->pxxDayReal($c_b_bk.",cid",$cid,"网站_收费_补扣停车",$row['补扣停车费'],$ctime);
    }
    if($c_b_gl>0){
        CTLog::G()->pxxDayReal($c_b_gl.",cid",$cid,"网站_收费_补扣管理",$row['补扣管理费'],$ctime);
    }
    if($c_j_tx>0){
        CTLog::G()->pxxDayReal($c_j_tx.",cid",$cid,"网站_收费_加急提现",$row['加急提现费'],$ctime);
    }
    if($c_d_ss>0){
        CTLog::G()->pxxDayReal($c_d_ss.",cid",$cid,"网站_收费_垫资损失收回",$row['垫资损失收回费'],$ctime);
    }
    if($c_h_hb>0){
        CTLog::G()->pxxDayReal($c_h_hb.",cid",$cid,"网站_支出_活动红包",$row['活动红包支出费用'],$ctime);
    }
    if($c_lx_glf>0){
        CTLog::G()->pxxDayReal($c_lx_glf.",cid",$cid,"利息管理费",$row['理财利息管理费'],$ctime);
    }
    if($c_re_sxf>0){
        CTLog::G()->pxxDayReal($c_re_sxf.",cid",$cid,"赎回手续费",$row['赎回手续费'],$ctime);
    }
}
$rows = $dbselect->GetRows("SELECT SUM(-money) AS 续投金额,COUNT(DISTINCT u.uid) AS 继投人数,COUNT(u.uid) AS 继投笔数, 
SUBSTR( qtime_h, 1, 10 ) AS qtime_h
FROM  `04a_5flow_uid` u LEFT JOIN 05b_1tenderfinal b ON u.objid2=b.bid AND u.uid=b.uid  
WHERE b.status=1 AND atnm='uid_keti' AND flowty='toubiao' $sfwhere
group by SUBSTR( qtime_h, 1, 10 )");
foreach($rows as &$row){
    $ctime  = $row['qtime_h'];
    $xtje   = $row['续投金额'];
    $xtrs   = $row['继投人数'];
    $xtbs   = $row['继投笔数'];
    if($xtbs>0){
        CTLog::G()->pxxDayReal($xtbs.",sid",1,"回款_继投_金额",$xtje,$ctime);
        CTLog::G()->pxxDayReal("sid",1,"回款_继投_人数",$xtrs,$ctime);
    }   
}


$rows = $dbselect->GetRows("SELECT SUM(-money) AS 提现金额,COUNT(DISTINCT uid) AS 提现人数,COUNT(uid) AS 提现笔数, 
SUBSTR( qtime_h, 1, 10 ) AS qtime_h
FROM  `04a_5flow_uid`  
WHERE atnm='uid_keti' AND flowty='tixian'  $sfwhere
group by SUBSTR( qtime_h, 1, 10 )");
foreach($rows as &$row){
    $ctime  = $row['qtime_h'];
    $xtje   = $row['提现金额'];
    $txrs   = $row['提现人数'];
    $txbs   = $row['提现笔数'];
    if($txbs>0){
        CTLog::G()->pxxDayReal($txbs.",sid",1,"回款_提现_金额",$xtje,$ctime);
        CTLog::G()->pxxDayReal("sid",1,"回款_提现_人数",$txrs,$ctime);
    }   
}